Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Water - Kareha & Leah #5

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open

Water - Kareha & Leah #5

wants to merge 42 commits into from

Conversation

scottzec
Copy link

@scottzec scottzec commented Oct 9, 2020

Assignment Submission: Slack CLI

Congratulations! You're submitting your assignment. Please reflect on the assignment with these questions.

Reflection

Question Answer
How did you go about exploring the Slack API? Did you learn anything that would be useful for your next project involving an API? We spent time trying to understand the arguments that each method accepted. We also lingered on certain points, i.e. what type of recipient you could post a message to, in the method documentation pages.
Give a short summary of the request/response cycle. Where does your program fit into that scheme? The human user makes a request via the CLI to our program, the client. Our program returns an appropriate response to the user containing information it received from the server via the API.
How does your program check for and handle errors when using the Slack API? If the GET request isn't successful for any reason, the SlackAPI Error is raised. We check that our GET requests are successful every time we use the API. We return a string to check that the send message method successfully POSTs that message.
How did the design and organization of your project change over time? Our design we sketched on Monday evening was fairly similar to Ada's design. We then worked within that framework for the duration of the project.
Did you use any of the inheritance idioms we've talked about in class? How? We used Recipient, an abstract class. We defined template methods in that abstract class and used them throughout our subclasses User, Channel and Workspace.
How does VCR aid in testing a program that uses an API? Instead of continually creating new API calls that could cause our API to overwhelm Slack's servers and potentially negatively affect our access, VCR runs the API call one time and saves a "recording" of that call for future tests to access instead of a new API call.

Copy link

@beccaelenzil beccaelenzil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slack CLI

Major Learning Goals/Code Review

Criteria yes/no, and optionally any details/lines of code to reference
Practices best practices working with APIs. The .env is not checked into git, and no API token was directly used in the Ruby code without ENV. ✔️
Practices error handling with APIs. For all pieces of code that make an API call, it handles API requests that come back with errors/error status codes appropriately. ✔️
Implements inheritance and inheritance idioms. There is a Recipient class. User and Channel inherit from Recipient. In Recipient, there are appropriate methods defined that are used in both User and Channel. Some may be implemented. Some may be template methods. ✔️
Practices clean code. lib/slack.rb only interacts with Workspace to show a separation of responsibilities. Complex logic is broken into smaller helper methods. ✔️
Practices instance methods vs. class methods appropriately. The methods to list all Channels or Users is likely a class method within those respective classes. ✔️
Practices best practices for testing. The project has and uses VCR mocking when running tests, and can run offline. ✔️
Practices writing tests. The User, Channel, and Workspace classes have unit tests. ✔️
Practices writing tests. There are tests for sending messages (the location of these tests may differ, but is likely in Recipient) ✔️
Practices git with at least 15 small commits and meaningful commit messages ✔️

Functional Requirements

Functional Requirement yes/no
As a user of the CLI program, I can list users and channels ✔️
As a user of the CLI program, I can select users and channels ✔️
As a user of the CLI program, I can show the details of a selected user or channel ✔️
As a user of the CLI program, when I input something inappropriately, the program runs without crashing If I try to send a message before selecting a user/channel, the error bubbles up. Consider how you could gracefully handle this.

Overall Feedback

Excellent job overall. This code is well-written and well-tested. It is clear to me that the learning goals around understanding the request/response cycle, consuming an API, and implementing a design using inheritance from scratch were all met.

I've left a few inline comments for you to review below focused on ways to enhance user experience. The logic in the slack.rb code allows exceptions to bubble up to the user.

Of particular note, you've done a great job breaking out functionality into helper methods. Keep up the hard work!

Overall Feedback Criteria yes/no
Green (Meets/Exceeds Standards) 7+ in Code Review && 3+ in Functional Requirements ✔️
Yellow (Approaches Standards) 6+ in Code Review && 2+ in Functional Requirements
Red (Not at Standard) 0-5 in Code Review or 0,1 in Functional Reqs, or assignment is breaking/doesn’t run with less than 5 minutes of debugging

Code Style Bonus Awards

Was the code particularly impressive in code style for any of these reasons (or more...?)

Quality Yes?
Descriptive/Readable
Concise
Logical/Organized

def validate_property_type(property_type)
property_type.downcase!
valid_property_types = ["name", "id"]
return false unless valid_property_types.include?(property_type)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of a postfix conditional.

Comment on lines +19 to +22
until validate_property_type(property_type)
puts "Please enter either name or ID"
property_type = gets.chomp
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great use of a helper method.

Comment on lines +30 to +32
if recipient == nil
puts "This #{recipient_string} doesn't exist! Exiting..."
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider writing this as a postfix conditional.

end
@selected = selected_user

return selected_user

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider whether selected_user needs to be returned, as it is stored in the instance variable @selected

Comment on lines +31 to +35
if property == "id"
selected_channel = channels.find{|channel_instance| channel_instance.slack_id == channel}
elsif property == "name"
selected_channel = channels.find{|channel_instance| channel_instance.channel_name == channel}
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great use of the enumerable method `find1

Comment on lines +49 to +52
def validate_post(response)
raise SlackAPIError.new("API call failed with code #{response.code} and error #{response['error']}") if response["ok"] == false
return "Thank you this message was sent"
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great use of a helper method.


def validate_input(input)
input.downcase!
raise ArgumentError.new("Not a valid input") unless VALID_INPUT.include?(input)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argument errors are great to raise in your source code, but in your CLI code, you should consider how you can handle invalid user input so that the error doesn't bubble up and the user gets the opportunity to correct their mistake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants